package com._23DesignPattern._action._visitor.demo1;

/**
 * @Author: huangya
 * @Date: 2020/09/12
 * @Description:
 */
public class VisitorPattern {

    public static void main(String[] args) {
        /** ElementA + ElementB */
        ObjectStructure os = new ObjectStructure();
        os.add(new ConcreteElementA());
        os.add(new ConcreteElementB());

        Visitor visitorA = new ConcreteVisitorA();
        /**
         * ElementA.accept(visitorA) ---> visitorA.visit(ElementA) ---> ElementA.operationA()
         * ElementB.accept(visitorA) ---> visitorA.visit(ElementB) ---> ElementB.operationB()
         */
        os.accept(visitorA);

        System.out.println("------------------------");

        Visitor visitorB = new ConcreteVisitorB();
        /**
         * ElementA.accept(visitorB) ---> visitorB.visit(ElementA) ---> ElementA.operationA()
         * ElementB.accept(visitorB) ---> visitorB.visit(ElementB) ---> ElementB.operationB()
         */
        os.accept(visitorB);
    }
}
